package com.study.factorybean;

import lombok.Data;
import org.springframework.beans.factory.FactoryBean;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @Author chenyeqing
 * @Date 2021/9/16 23:03
 */
@Data
public class ConnectionFactoryBean implements FactoryBean<Connection> {
    private String className;
    private String url;
    private String username;
    private String password;
    @Override
    public Connection getObject() throws Exception {
        Class.forName(className);
        Connection connection = DriverManager.getConnection(url, username, password);

        return connection;
    }

    @Override
    public Class<Connection> getObjectType() {
        return Connection.class;
    }

    @Override
    public boolean isSingleton() {
        return false;
    }
}
